//
//  CardCell.m
//  DriftDog
//
//  Created by rimi on 15/9/8.
//  Copyright (c) 2015年 廖马林. All rights reserved.
//

#import "CardCell.h"
@interface CardCell ()
@property (nonatomic , assign)NSInteger sectionInterger;
@property (nonatomic , assign)NSInteger rowInterger;
@property (nonatomic , assign)NSInteger addInterger;
@property (nonatomic , strong)NSMutableArray *arry;

@end
@implementation CardCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self initliedUserinterface];
        
    }
    return self;
  
}

-(void)initliedUserinterface{
    _addInterger=1;
    [self rectHight:self.contentLabel.text];
    [self addSubview:self.originView];
    [self.originView addSubview:self.infoView];
    [self.originView addSubview:self.photoView];
    [self.originView addSubview:self.otherView];
    [self.infoView addSubview:self.Headimage];
    [self.infoView addSubview:self.userLabel];
    [self.infoView addSubview:self.timeLabel];
    [self.infoView addSubview:self.contentLabel];
    [self.otherView addSubview:self.shareButton];
    [self.otherView addSubview:self.suportButton];
    [self.otherView addSubview:self.chatButton];
    
    
    if (_addInterger<=0) {
        
        [_photoView setHidden:YES];
        
        
    }else{
    
        if (!_photoImage) {
            for (int i=0; i<_addInterger; i++) {
                
                
                _rowInterger=i/3;
                _sectionInterger=i%3;
                
                _photoImage=[[UIImageView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(10+145*_sectionInterger, 10+65*_rowInterger, 100, 55), NO)];
                _photoImage.backgroundColor=[UIColor whiteColor];
                [self.photoView addSubview:_photoImage];
                
            }
        }

    }
    
    
}

-(UIView *)originView{
     NSInteger a=(_addInterger-1)/3;
    if (_addInterger<=0) {
        if (!_originView) {
            _originView=({
                
                UIView *view=[[UIView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 0, ORIGIN_WIDTH, 110+_rect.size.height/DHFlexibleVerticalMutiplier()), NO)];
                
                view.backgroundColor=[UIColor redColor];
                view;
            });
        }

    }
    else{
    if (!_originView) {
        _originView=({
            
            UIView *view=[[UIView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 0, ORIGIN_WIDTH, 190+_rect.size.height/DHFlexibleVerticalMutiplier()+70*a), NO)];
            
            view.backgroundColor=[UIColor redColor];
            view;
        });
    }
}
    return _originView;
    
}
-(UIView *)infoView{
    
   
    if (!_infoView) {
        _infoView=({
            UIView *view=[[UIView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 0, ORIGIN_WIDTH, 70+_rect.size.height/DHFlexibleVerticalMutiplier()), NO)];
            view.backgroundColor=[UIColor yellowColor];
            view;
        });
    }
    
    return _infoView;
    
}

-(UIView *)photoView{
   NSInteger a=(_addInterger-1)/3;
    if (!_photoView) {
        _photoView=({
            UIView *view=[[UIView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 72+_rect.size.height/DHFlexibleVerticalMutiplier(), ORIGIN_WIDTH, 80+70*a), NO)];
            view.backgroundColor=[UIColor blackColor];
            view;
        });
    }
    
    return _photoView;
    
}
-(UIView *)otherView{
   NSInteger a=(_addInterger-1)/3;
    if (_addInterger<=0) {
        
        if (!_otherView) {
            _otherView=({
                
                UIView *view=[[UIView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0,71+_rect.size.height/DHFlexibleVerticalMutiplier(), ORIGIN_WIDTH, 40), NO)];
                view.backgroundColor=[UIColor orangeColor];
                view;
            });
        }

    }
    else{
        if (!_otherView) {
            _otherView=({
                
                UIView *view=[[UIView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 148+_rect.size.height/DHFlexibleVerticalMutiplier()+70*a, ORIGIN_WIDTH, 40), NO)];
                view.backgroundColor=[UIColor orangeColor];
                view;
            });
        }

    
    }
    
    return _otherView;
    
}

-(UIImageView*)Headimage{
    if (!_Headimage) {
        _Headimage=[[UIImageView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(10, 10, 50, 50) , NO)];
        _Headimage.backgroundColor=[UIColor redColor];
        _Headimage.layer.cornerRadius=25*DHFlexibleHorizontalMutiplier();
        _Headimage.clipsToBounds=YES;
        
    }
    
    return _Headimage;
    
}

-(UILabel*)userLabel{
    
    if (!_userLabel) {
        _userLabel=[[UILabel alloc]initWithFrame:DHFlexibleFrame(CGRectMake(68, 14, 200, 20), NO)];
        _userLabel.backgroundColor=[UIColor redColor];
    }
    return _userLabel;
    
}
-(UILabel*)timeLabel{
    
    if (!_timeLabel) {
        _timeLabel=[[UILabel alloc]initWithFrame:DHFlexibleFrame(CGRectMake(68, 40, 200, 15), NO)];
        _timeLabel.backgroundColor=[UIColor redColor];
    }
    return _timeLabel;
    
}

-(UILabel*)contentLabel{
    
    if (!_contentLabel) {
        _contentLabel=[[UILabel alloc]init];
        _contentLabel.font=[UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
        _contentLabel.numberOfLines=0;

        NSString *text = @"本tdeeeyuuuuuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaatdeeeyuuuuuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        _contentLabel.text = text;
        _contentLabel.backgroundColor=[UIColor redColor];
        _contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
        [self rectHight:_contentLabel.text];
        _contentLabel.frame=CGRectMake(68*DHFlexibleVerticalMutiplier(), 70*DHFlexibleVerticalMutiplier(), _rect.size.width, _rect.size.height);//DHFlexibleFrame(CGRectMake(68, 10, _rect.size.width, _rect.size.height), NO);
//         _contentLabel.frame=DHFlexibleFrame(CGRectMake(68, 40, 340, 0), NO);
//
//       [_contentLabel sizeToFit];
        
        }
  
    return _contentLabel;
    
}

-(UIImageView*)photoImage{
    if (!_photoImage) {
        
            _photoImage=[[UIImageView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(10, 10, 100, 55), NO)];
            _photoImage.backgroundColor=[UIColor whiteColor];
        
       

    }
    
    return _photoImage;
    
}

-(UIButton*)shareButton{
    
    if (!_shareButton) {
        _shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _shareButton.frame = DHFlexibleFrame(CGRectMake(30, 10, 90, 25), NO);
        _shareButton.backgroundColor=[UIColor colorWithRed:105/255.f green:180/255.f blue:159/255.f alpha:1];
        _shareButton.layer.cornerRadius=13*DHFlexibleHorizontalMutiplier();
        [_shareButton setImage:[UIImage imageNamed:@"帖子分享图标.png"] forState:UIControlStateNormal];
        [_shareButton setImage:[UIImage imageNamed:@"帖子分享图标.png"] forState:UIControlStateSelected];
        [_shareButton setImage:[UIImage imageNamed:@"帖子分享图标.png"] forState:UIControlStateHighlighted];
        _shareButton.clipsToBounds=YES;
        _shareButton.imageEdgeInsets = UIEdgeInsetsMake(5, 30, 5, 30);
        
    }
    return _shareButton;
    
}
-(UIButton*)suportButton{
    
    if (!_suportButton) {
        _suportButton=[[UIButton alloc]initWithFrame:DHFlexibleFrame(CGRectMake(160, 10, 90, 25), NO)];
        _suportButton.backgroundColor=[UIColor colorWithRed:105/255.f green:180/255.f blue:159/255.f alpha:1];
        _suportButton.layer.cornerRadius=13*DHFlexibleHorizontalMutiplier();
        [_suportButton setImage:[UIImage imageNamed:@"帖子喜欢图标.png"] forState:UIControlStateNormal];
        [_suportButton setImage:[UIImage imageNamed:@"帖子喜欢图标.png"] forState:UIControlStateSelected];
        [_suportButton setImage:[UIImage imageNamed:@"帖子喜欢图标.png"] forState:UIControlStateHighlighted];

        _suportButton.clipsToBounds=YES;
        _suportButton.imageEdgeInsets = UIEdgeInsetsMake(5, 20, 5, 40);
        [_suportButton setTitle:@"0" forState:UIControlStateNormal];
        [_suportButton setTitleEdgeInsets:UIEdgeInsetsMake(5, -55/DHFlexibleHorizontalMutiplier(), 5, 20)];
        _suportButton.titleLabel.font=[UIFont systemFontOfSize:18*DHFlexibleHorizontalMutiplier()];
    }
    return _suportButton;
    
}
-(UIButton*)chatButton{
    
    if (!_chatButton) {
        _chatButton=[[UIButton alloc]initWithFrame:DHFlexibleFrame(CGRectMake(290, 10, 90, 25), NO)];
        _chatButton.backgroundColor=[UIColor colorWithRed:105/255.f green:180/255.f blue:159/255.f alpha:1];
        _chatButton.layer.cornerRadius=13*DHFlexibleHorizontalMutiplier();
        [_chatButton setImage:[UIImage imageNamed:@"帖子评价图标.png"] forState:UIControlStateNormal];
        [_chatButton setImage:[UIImage imageNamed:@"帖子评价图标.png"] forState:UIControlStateSelected];
        [_chatButton setImage:[UIImage imageNamed:@"帖子评价图标.png"] forState:UIControlStateHighlighted];
        _chatButton.clipsToBounds=YES;
        _chatButton.imageEdgeInsets = UIEdgeInsetsMake(5, 20, 5, 40);
        [_chatButton setTitle:@"0" forState:UIControlStateNormal];
        [_chatButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_chatButton setTitleEdgeInsets:UIEdgeInsetsMake(5, -55/DHFlexibleHorizontalMutiplier(), 5, 20)];
        _chatButton.titleLabel.font=[UIFont systemFontOfSize:18*DHFlexibleHorizontalMutiplier()];
    }
    return _chatButton;
    
}
-(void)rectHight:(NSString*)string{

    _rect = [string boundingRectWithSize:DHFlexibleSize(CGSizeMake(340, MAXFLOAT), NO) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()]} context:nil];

}
@end
